//
//  weChatResult.m
//  test1
//
//  Created by gengzhangjia on 15/7/29.
//  Copyright (c) 2015年 gengzhangjia. All rights reserved.
//

#import "weChatResult.h"

@interface weChatResult ()
{
    NSString *_resultErrorInfo;
    WeChatResultCode _resultCode;
}
@end

@implementation weChatResult

- (instancetype)init
{
    if(self =[super init])
    {
        _resultCode =WeChatResultCodeNone;
    }
    return self;
}
+ (instancetype) success
{
    weChatResult *result = [[weChatResult alloc] init];
    [result setResultCode:WeChatResultCodeSuccess];
    [result setResultErrorInfo:@"请求成功"];
    return result;
}

+ (instancetype) notInstallApp
{
    weChatResult *result = [[weChatResult alloc] init];
    [result setResultCode:WeChatResultCodeUnInstalled];
    [result setResultErrorInfo:@"未安装微信"];
    return result;
}

+ (instancetype) notSupportAPI
{
    weChatResult *result = [[weChatResult alloc] init];
    [result setResultCode:WeChatResultCodeUnSupport];
    [result setResultErrorInfo:@"微信不支持"];
    return result;
}

+ (instancetype) notError
{
    weChatResult *result = [[weChatResult alloc] init];
    [result setResultCode:WeChatResultCodeNone];
    [result setResultErrorInfo:@"未知错误"];
    return result;
}

+ (instancetype) createConditionWithErrorCode:(WeChatResultCode) resultCode
                                   resultInfo:(NSString *) resultInfo
{
    weChatResult *result =[[weChatResult alloc] init];
    [result setResultCode:resultCode];
    [result setResultErrorInfo:resultInfo];
    return  result;
}

- (WeChatResultCode) resultCode
{
    return _resultCode;
}

- (void) setResultCode:(WeChatResultCode) resultCode
{
    _resultCode = resultCode;
}

- (NSString *) resultErrorInfo
{
    return _resultErrorInfo;
}

- (void) setResultErrorInfo:(NSString *) resultErrorInfo
{
    _resultErrorInfo = resultErrorInfo;
}

- (void) parseResult:(BaseResp *) resp
{
    switch (resp.errCode) {
        case WXSuccess:
            _resultCode = WeChatResultCodeSuccess;
            _resultErrorInfo = @"请求成功";
            break;
        case WXErrCodeCommon:
            _resultCode = WeChatResultCodeCommon;
            _resultErrorInfo = @"普通错误类型";
            break;
        case WXErrCodeUserCancel:
            _resultCode = WeChatResultCodeUserCancel;
            _resultErrorInfo = @"用户点击取消并返回";
            break;
        case WXErrCodeSentFail:
            _resultCode = WeChatResultCodeSendFail;
            _resultErrorInfo = @"发送失败";
            break;
        case WXErrCodeAuthDeny:
            _resultCode = WeChatResultCodeAuthDeny;
            _resultErrorInfo = @"授权失败";
            break;
        case WXErrCodeUnsupport:
            _resultCode = WeChatResultCodeUnSupport;
            _resultErrorInfo = @"微信不支持";
            break;
        default:
            _resultCode = WeChatResultCodeNone;
            _resultErrorInfo = @"未知错误";
            break;
    }
}
@end
